<?php
	@$UserID = $_COOKIE['studialuserid'];
	@$HomeID = $_POST['homeid'];	
	@$TopicID = $_POST['topicid'];
	@$Comment = $_POST['comment'];
	@$Link = $_POST['link'];
		
	if ( !$UserID || !$TopicID || empty($Comment) )
	{
		header("location: ../users/homeboard.php?id=".$HomeID);
	}
	
	
	@ $db = mysql_pconnect("localhost","root","");
		
	if(!$db)
	{
		echo "<h2>Database does not exist!</h2>";
		exit;
	}
			
	mysql_set_charset('UTF8');
	mysql_select_db('studial');
		
	$arr = getdate();
	$time = "$arr[year]-$arr[mon]-$arr[mday] $arr[hours]:$arr[minutes]:$arr[seconds]";
		
	$result = "INSERT INTO `comments` (`user_id`, `topic_id`, `path`, `content`, `datecommented`, `numliked`) VALUES ('".$UserID."', '".$TopicID."', '".$Link."', '".$Comment."', '".$time."', 0)";
		
	$query = mysql_query($result) or die('Error, query failed');
		
	header("location: ../users/homeboard.php?id=".$HomeID);
?>
